INPUT AND OUTPUT¶
1. WAP to input two integers using Parameters and find their Sum and product¶
In [2]:
a = int(input("Enter the first Number: "))
b = int(input("Enter the second Number: "))
s = a+b
p = a*b
print("Sum: ", s)
print("Product: ",p)
Sum: 110 Product: 2925
2. WAP to input five integers and find their average.¶
In [3]:
a = int(input("Enter the first Number: "))
b = int(input("Enter the second Number: "))
c = int(input("Enter the third Number: "))
d = int(input("Enter the fourth Number: "))
e = int(input("Enter the fifth Number: "))
avg = (a+b+c+d+e)/5
print("Averge: ",avg)
Averge: 6.2
3. WAP to input two integers using Scanner and find the product of their sum and difference.¶
In [ ]:
wrong ques
4. WAP to input three integers and find the difference between their sum and their average.¶
In [4]:
a = int(input("Enter the first Number: "))
b = int(input("Enter the second Number: "))
c = int(input("Enter the third Number: "))
d = (a+b+c) - ((a+b+c)/3)
print("The difference between their sum and their average: ",d)
The difference between their sum and their average: 14.0
5. WAP to input the Principal, Rate and Time for a certain amount of money and print the Simple Interest.¶
In [5]:
p = int(input("Enter the Principle: "))
t = int(input("Enter the number of Years: "))
r = int(input("Enter the Rate Of Interest: "))
i = (p*r*t)/100
print("Interest: ",i)
Interest: 300.0
6. WAP to input the length and breadth of a rectangle and find its area and perimeter.¶
- Note:
- Area of a rectangle=length*breadth
- Perimeter of a rectangle=2*(length + breadth)
In [7]:
l = int(input("Enter the Length: "))
b = int(input("Enter the Breadth: "))
a = l*b
p = 2*(l+b)
print("Area: ", a)
print("Perimeter: ", p)
Area: 300 Perimeter: 74
7. WAP to input the radius of a circle and find its area and perimeter.¶
- Note:
- Area of a circle=22/7* $radius^2$
- Circumference of a circle= 2 * 22/7 * radius
In [8]:
r = int(input("Enter the Radius: "))
a = (22/7) * r * r
p = 2 * (22/7) * r
print("Area: ", a)
print("Perimeter: ", p)
Area: 154.0 Perimeter: 44.0
8. WAP to input the length, breadth and height of a cuboid and find its Volume and Total Surface Area.¶
- Note:
- Volume of a cuboid= length * breadth * height
- Total Surface Area=2 * (length * breadth +breadth * height + height * length)
In [2]:
l = (int)(input("Enter the Length: "))
b = (int)(input("Enter the Breadth: "))
h = (int)(input("Enter the Height: "))
v = l*b*h
sa = 2 *((l*b) + (b*h) + (l*h))
print("Volume: ", v)
print("Surface Area: ", sa)
Volume: 260325 Surface Area: 25430
9. WAP to input the radius and height of a cylinder and find its volume and total surface area.¶
In [3]:
r = int(input("Enter the radius: "))
h = int(input("Enter the height: "))
v = (22/7) * r * r * h
sa = ((22/7) * r) * (4 * r + 2 * h)
print("Volume: ", v)
print("Surface Area: ", sa)
Volume: 2156.0 Surface Area: 1232.0
10. WAP to input three integers and find the sum of the last digit of the numbers.¶
- For example
- if the inputs are: 12 26 35
- Output: Sum of the last digit of the integers are: 13
In [4]:
a = int(input("Enter the first Number: "))
b = int(input("Enter the second Number: "))
c = int(input("Enter the third Number: "))
s = (a % 10) + (b % 10) + (c % 10)
print("Sum of last digit of numbers: ", s)
Sum of last digit of numbers: 13
11. WAP to input the temperature in Fahrenheit and change it to Celsius.¶
- Note:
- The relation between Fahrenheit and Celsius is given by the formula: $$C = \frac 59 \times (F-32)$$
- Where C$\rightarrow$Celsius and F$\rightarrow$Fahrenheit
In [6]:
f = int(input("Enter the Temperature in Fahrenheit: "))
c = (5/9) * (f-32)
print("Temperature in Celsius: ", c)
Temperature in Celsius: 15.0
12. WAP to input time in seconds and display the time broken up as hours, minutes and seconds.¶
- For Example:
- INPUT: Enter Time in Seconds: 4326
- OUTPUT:
- Time in hours: 1
- Time in minutes: 12
- Time in seconds: 6
In [8]:
s = int(input("Enter time in seconds: "))
h = int(s / 3600)
s = s % 3600
m = int(s / 60)
s = s % 60
print("Time in Hours: ", h)
print("Time in Minutes: ", m)
print("Time in Seconds: ", s)
Time in Hours: 1 Time in Minutes: 12 Time in Seconds: 6
13. WAP to input a floating point number and round it off to the nearest integer.¶
- For Example:
- INPUT: Enter a floating point number: 12.3 \
- OUTPUT: Rounded off to nearest integer:12
- INPUT: Enter a floating point number: 14.5
- OUTPUT: Rounded off to two places of decimal:15
In [1]:
a = float(input("Enter the floating number: "))
b = round(a)
print("The Rounded of number to nearest integer: ", b)
The Rounded of number to nearest integer: 12
14. WAP to input a floating point number and round it off to two places of decimal.¶
- For Example:
- INPUT: Enter a floating point number: 12.367
- OUTPUT: Rounded off to two places of decimal:12.37
- INPUT: Enter a floating point number: 14.563
- OUTPUT: Rounded off to two places of decimal:14.56
In [2]:
a = float(input("Enter the floating number: "))
b = round(a,2)
print("The Rounded of number to two decimal places: ", b)
The Rounded of number to two decimal places: 12.57
15. WAP to input two integers (say a and b) and interchange their values and display the result.(using third variable)¶
- For Example:
- INPUT: Enter two integers: 15 36
- OUTPUT: Before interchange: a=15 and b=36 after interchange: a=36 and b=15
- Please note that you can take just one variable other than a and b for interchanging.
In [10]:
a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))
print("a = ", a)
print("b = ", b)
c = a
a = b
b = c
print("Swapping the Values")
print("a = ", a)
print("b = ", b)
a = 15 b = 36 Swapping the Values a = 36 b = 15
16. WAP to input the time in hours, minutes and seconds and print it in seconds.¶
- For Example:
- INPUT:
- Enter time in hours: 1
- Enter time in minutes: 12
- Enter time in seconds: 6
- OUTPUT: Time in seconds:4326
- INPUT:
In [20]:
h = int(input("Enter time in hours: "))
m = int(input("Enter time in minutes: "))
s = int(input("Enter time in seconds: "))
s = s + (h*3600) + (m*60)
print("Time in Seconds: ",s)
Time in Seconds: 4326
17. WAP to input three integers and find their sum, without using the mathematical operator +¶
In [5]:
import math as m
a = int(input("Enter the first Number: "))
b = int(input("Enter the second Number: "))
c = int(input("Enter the third Number: "))
s = m.fsum([a,b,c])
print("Sum: ", s)
Sum: 190.0
18. WAP to enter the perimeter of a square and find its perimeter.¶
- For Example,
- INPUT: Enter the perimeter of a square: 64
- OUTPUT: Area of the square is: 256
In [6]:
p = int(input("Enter the perimeter of square: "))
s = p / 4
a = s * s
print("Area of the square: ", a)
Area of the square: 81.0
19. WAP to enter the length and area of a rectangle and find its perimeter.¶
- For Example,
- INPUT:
- Enter the length of the rectangle:12
- Enter the area of the rectangle: 72
- OUTPUT: Perimeter of the rectangle:36.0
- INPUT:
In [9]:
l = int(input("Enter the length of the rectangle: "))
a = int(input("Enter the area of the rectangle: "))
b = a / l
p = 2 * (l + b)
print("Perimeter of the rectangle: ", p)
Perimeter of the rectangle: 36.0
20. WAP to input the Basic Pay of an employee and find the gross pay of the employee for the following allowances and deductions.¶
- Dearness Allowance = 25% of Basic Pay
- House Rent Allowance=15% of Basic Pay
- Provident Fund=8.33% of Basic Pay
- Net Pay=Basic Pay + Dearness Allowance + House Rent Allowance
- Gross Pay= Net Pay – Provident Fund
In [11]:
bp = int(input("Enter the Basic Pay amount: "))
da = 0.25 * bp
hra = 0.15 * bp
pf = 0.833 * bp
np = bp + da + hra
gp = np - pf
print("Gross Pay of the employee: ", gp)
Gross Pay of the employee: 25515.0
21. WAP to input the dimensions of a rectangle and find the area of that square whose perimeter is equal to the perimeter of the rectangle.¶
In [13]:
l = int(input("Enter the length of the Retangle: "))
b = int(input("Enter the breadth of the Rectangle: "))
rp = 2 * (l + b)
ss = rp / 4
sa = ss * ss
print("Area of the square whose perimeter is equal to that of the rectangle : ", sa)
Area of the square whose perimeter is equal to that of the rectangle : 7744.0
22. WAP to input an integer and if positive change it to negative and if negative change it to positive.¶
- INPUT: Enter an integer: 12
- OUTPUT: Sign changed:-12
- INPUT: Enter an integer: -14
- OUTPUT: Sign changed: 14
In [15]:
a = int(input("Enter the number: "))
b = - a
print("Sign Changed: ",b)
Sign Changed: -56
23. If the marks obtained by a student in five different subjects are input through the keyboard, WAP to find out the aggregate marks and percentage marks obtained by the student. Assume that the maximum marks that can be obtained by a student in each subject is 100.¶
In [16]:
a = int(input("Enter the marks for 1st subject: "))
b = int(input("Enter the marks for 2nd subject: "))
c = int(input("Enter the marks for 3rd subject: "))
d = int(input("Enter the marks for 4th subject: "))
e = int(input("Enter the marks for 5th subject: "))
am = a + b + c + d + e
pm = am/5
print("Aggregate marks: ", am)
print("Percentage marks: ", pm)
Aggregate marks: 405 Percentage marks: 81.0
24. If the total selling price of 15 items and the total profit earned on them is input through the keyboard, WAP to find the cost price of one item.¶
In [19]:
sp = int(input("Enter the total Selling Price: "))
p = int(input("Enter the profit: "))
cppi = (sp - p) / 15
print("Cost Price of one item: ",cppi)
Cost Price of one item: 1000.0
Mathematical Methods¶
1. WAP to input the area of a square and find its perimeter.¶
In [1]:
import math as m
a = int(input("Enter the area of the square: "))
s = m.sqrt(a)
p = 4 * s
print("The perimeter of the square: ", p)
The perimeter of the square: 36.0
2. WAP to input the length and breadth of a rectangle and find its diagonal.¶
In [2]:
import math as m
l = int(input("Enter the length of the rectangle: "))
b = int(input("Enter the breadth of the rectangle: "))
d = m.sqrt((l*l)+(b*b))
print("The Diagonal of rectangle: ", d)
The Diagonal of rectangle: 5.0
3. WAP that outputs the results of the following evaluations based on the number entered by the user.¶
- Cube root of the number
- Absolute value of the number
- Square root of the number
- Random numbers between 0 and 1.
In [7]:
import math as m
import random as r
a = int(input("Enter an integer for cube root: "))
cr = m.cbrt(a)
print("Cube root is: ", cr)
b = float(input("Enter an number for absolute value: "))
ab = abs(b)
print("Absolute Value: ", ab)
c = int(input("Enter an integer for square root: "))
sr = m.sqrt(c)
print("Square Root is", sr)
r = r.uniform(0,1)
print("Random number between 0 and 1: ", r)
Cube root is: 3.0
Absolute Value: 5689.0
Square Root is 16.0 Random number between 0 and 1: 0.26779887802959257
4. WAP to input the radius of a circle and find its area and circumference.¶
In [3]:
r = int(input("Enter the Radius: "))
a = (22/7) * r * r
p = 2 * (22/7) * r
print("Area: ", a)
print("Perimeter: ", p)
Area: 154.0 Perimeter: 44.0
5. WAP to input the area of a circle and find its circumference.¶
In [ ]:
import math as m
a = int(input("Enter the Area: "))
r = m.sqrt(a/(22/7))
c = 2 * (22/7) * r
print("Circumference: ", c)
6. WAP to input three integers and find the sum of their cube roots.¶
In [1]:
import math as m
a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))
c = int(input("Enter the third number: "))
s = m.pow(a,(1/3)) + m.pow(b,(1/3)) + m.pow(c,(1/3))
print("The sum of cube roots of the number: ", s)
The sum of cube roots of the number: 9.0
7. WAP to input the principal, rate and time and find the compound interest.¶
In [2]:
import math as m
p = int(input("Enter the Principle: "))
t = int(input("Enter the number of Years: "))
r = int(input("Enter the Rate Of Interest: "))
a = p*(m.pow((1 + (r/100)),t))
ci = a-p
print("The amount after compound interest: ", a)
print("The Compound Interest: ",ci)
The amount after compound interest: 3163.297546240001 The Compound Interest: 663.2975462400009
8. WAP to input the three sides of a triangle and find the perimeter and area of the triangle. If a, b and c are the 3 sides then, Perimeter=a + b + c $$A = \sqrt{s(s-a)(s-b)(s-c)}$$¶
In [3]:
import math as m
a = int(input("Enter the first side: "))
b = int(input("Enter the second side: "))
c = int(input("Enter the third side: "))
p = a + b + c
print("The perimeter: ", p)
s = p / 2
ar = m.sqrt(s*(s-a)*(s-b)*(s-c))
print("The area: ", ar)
The perimeter: 12 The area: 6.0
9. WAP to input a real number (floating point number) and round it off to 2 places of decimal.¶
- For example,
- Input: 4.3678
- Output: 4.37
- Input: 24.3123
- Output: 24.31
In [4]:
a = float(input("Enter the floating number: "))
b = round(a,2)
print("The Rounded of number to two decimal places: ", b)
The Rounded of number to two decimal places: 4.37
10. WAP to input the length and breadth of a rectangle and find the perimeter of that square whose area is same as the area of the rectangle.¶
In [7]:
lr = int(input("Enter the length of the rectangle: "))
br = int(input("Enter the breadth of the rectangle: "))
pr = 2 * (lr + br)
ss = pr / 4
sa = ss * ss
print("Area of the square whose perimeter is the same as that of the rectangle: ", sa)
Area of the square whose perimeter is the same as that of the rectangle: 9.0
11. WAP to input three integers and find the sum of the cube roots of their last digits.¶
In [9]:
a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))
c = int(input("Enter the thrid number: "))
s = m.cbrt(a%10) + m.cbrt(b%10) + m.cbrt(c%10)
print("The sum of the cube roots of the last digit: ", s)
The sum of the cube roots of the last digit: 6.0
In [ ]: